// Copyright (c) 2024，D-Robotics.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/***************************************************************************
 * COPYRIGHT NOTICE
 * Copyright 2022 Horizon Robotics.
 * All rights reserved.
 ***************************************************************************/
#ifndef UTILITY_SENSOR_INC_OV5647_SETTING_H_
#define UTILITY_SENSOR_INC_OV5647_SETTING_H_

#ifdef __cplusplus
extern "C"
{
#endif

#define OV5647_CHIP_ID_MSB   0x300a
#define OV5647_CHIP_ID_LSB   0x300b
#define OV5647_TPG_CTRL      0x503d
#define OV5647_TPG_SET       0x4741
#define OV5647_FORMAT_CTRL00 0x4300
#define OV5647_FMT_MUX_CTRL  0x501f
#define OV5647_FRAME_CTRL01  0x4202
#define OV5647_SC_PLL_CTRL0  0x3034
#define OV5647_SC_PLL_CTRL2  0x3036


/* 1920x1080 30fps
 * NOTICE: vts/hts, clk maybe have problems, you have to ask ov sensor fae.
 * */
static uint32_t ov5647_1080p_settings[] = {
        0x0100, 0x00,
        0x0103, 0x01,
        0x3035, 0x11,
        0x3036, 0x64,
        0x303c, 0x11,
        0x3821, 0x06,
        0x3820, 0x00,
        0x370c, 0x0f,
        0x3612, 0x5b,
        0x3618, 0x04,
        0x5000, 0x06,
        0x5002, 0x40,
        0x5003, 0x08,
        0x5a00, 0x08,
        0x3000, 0xff,
        0x3001, 0xff,
        0x3002, 0xff,
        0x301d, 0xf0,
        0x3a18, 0x00,
        0x3a19, 0xf8,
        0x3c01, 0x80,
        0x3b07, 0x0c,
        0x380c, 0x09,
        0x380d, 0x70,
        0x380e, 0x04,
        0x380f, 0x50,
        0x3814, 0x11,
        0x3815, 0x11,
        0x3708, 0x64,
        0x3709, 0x12,
        0x3808, 0x07,
        0x3809, 0x80,
        0x380a, 0x04,
        0x380b, 0x38,
        0x3800, 0x01,
        0x3801, 0x5c,
        0x3802, 0x01,
        0x3803, 0xb4,//0xb2
        0x3804, 0x08,
        0x3805, 0xe3,
        0x3806, 0x05,
        0x3807, 0xf3,//0xf1
        0x3630, 0x2e,
        0x3632, 0xe2,
        0x3633, 0x23,
        0x3634, 0x44,
        0x3620, 0x64,
        0x3621, 0xe0,
        0x3600, 0x37,
        0x3704, 0xa0,
        0x3703, 0x5a,
        0x3715, 0x78,
        0x3717, 0x01,
        0x3731, 0x02,
        0x370b, 0x60,
        0x3705, 0x1a,
        0x3f05, 0x02,
        0x3f06, 0x10,
        0x3f01, 0x0a,
        0x3a08, 0x01,
        0x3a09, 0x4b,
        0x3a0a, 0x01,
        0x3a0b, 0x13,
        0x3a0d, 0x04,
        0x3a0e, 0x03,
        0x3a0f, 0x58,
        0x3a10, 0x50,
        0x3a1b, 0x58,
        0x3a1e, 0x50,
        0x3a11, 0x60,
        0x3a1f, 0x28,
        0x4001, 0x02,
        0x4004, 0x04,
        0x4000, 0x09,
        0x4050, 0x6e,
        0x4051, 0x8f,
        0x0100, 0x01,
        0x3000, 0x00,
        0x3001, 0x00,
        0x3002, 0x00,
        0x3017, 0xe0,
        0x301c, 0xfc,
        0x3636, 0x06,
        0x3016, 0x08,
        0x3827, 0xec,
        0x3018, 0x44,
        0x3035, 0x21,
        0x3106, 0xf5,
        0x3034, 0x1a,
        0x301c, 0xf8,
        0x3503, 0x03,
        0x4202, 0x00,//
};

static uint32_t ov5647_2lane_480p_init_setting[] = {
        0x0100, 0x00,
        0x0103, 0x01,
        0x3035, 0x11,
        0x3036, 0x46,
        0x303c, 0x11,
        0x3821, 0x06,
        0x3820, 0x41,
        0x370c, 0x03,
        0x3612, 0x59,
        0x3618, 0x00,
        0x5000, 0x06,
        0x5002, 0x40,
        0x5003, 0x08,
        0x5a00, 0x08,
        0x3000, 0xff,
        0x3001, 0xff,
        0x3002, 0xff,
        0x301d, 0xf0,
        0x3a18, 0x00,
        0x3a19, 0xf8,
        0x3c01, 0x80,
        0x3b07, 0x0c,
        0x380c, 0x07,
        0x380d, 0x3c,
        0x380e, 0x01,
        0x380f, 0xf8,
        0x3814, 0x35,
        0x3815, 0x35,
        0x3708, 0x64,
        0x3709, 0x52,
        0x3808, 0x02,
        0x3809, 0x80,
        0x380a, 0x01,
        0x380b, 0xe0,
        0x3800, 0x00,
        0x3801, 0x10,
        0x3802, 0x00,
        0x3803, 0x00,
        0x3804, 0x0a,
        0x3805, 0x2f,
        0x3806, 0x07,
        0x3807, 0x9f,
        0x3630, 0x2e,
        0x3632, 0xe2,
        0x3633, 0x23,
        0x3634, 0x44,
        0x3620, 0x64,
        0x3621, 0xe0,
        0x3600, 0x37,
        0x3704, 0xa0,
        0x3703, 0x5a,
        0x3715, 0x78,
        0x3717, 0x01,
        0x3731, 0x02,
        0x370b, 0x60,
        0x3705, 0x1a,
        0x3f05, 0x02,
        0x3f06, 0x10,
        0x3f01, 0x0a,
        0x3a08, 0x01,
        0x3a09, 0x2e,
        0x3a0a, 0x00,
        0x3a0b, 0xfb,
        0x3a0d, 0x02,
        0x3a0e, 0x01,
        0x3a0f, 0x58,
        0x3a10, 0x50,
        0x3a1b, 0x58,
        0x3a1e, 0x50,
        0x3a11, 0x60,
        0x3a1f, 0x28,
        0x4001, 0x02,
        0x4004, 0x02,
        0x4000, 0x09,
        0x3000, 0x00,
        0x3001, 0x00,
        0x3002, 0x00,
        0x3017, 0xe0,
        0x301c, 0xfc,
        0x3636, 0x06,
        0x3016, 0x08,
        0x3827, 0xec,
        0x3018, 0x44,
        0x3035, 0x21,
        0x3106, 0xf5,
        0x3034, 0x1a,
        0x301c, 0xf8,
        0x4800, 0x34,
        0x3503, 0x03,
        0x0100, 0x01,
};

static uint32_t ov5647_2lane_1944p_init_setting[] = {
        0x0100, 0x00,
        0x0103, 0x01,
        0x3034, 0x1a,
        0x3035, 0x21,
        0x3036, 0x69,
        0x303c, 0x11,
        0x3106, 0xf5,
        0x3821, 0x06,
        0x3820, 0x00,
        0x3827, 0xec,
        0x370c, 0x03,
        0x3612, 0x5b,
        0x3618, 0x04,
        0x5000, 0x06,
        0x5002, 0x40,
        0x5003, 0x08,
        0x5a00, 0x08,
        0x3000, 0x00,
        0x3001, 0x00,
        0x3002, 0x00,
        0x3016, 0x08,
        0x3017, 0xe0,
        0x3018, 0x44,
        0x301c, 0xf8,
        0x301d, 0xf0,
        0x3a18, 0x00,
        0x3a19, 0xf8,
        0x3c01, 0x80,
        0x3b07, 0x0c,
        0x380c, 0x0b,
        0x380d, 0x1c,
        0x3814, 0x11,
        0x3815, 0x11,
        0x3708, 0x64,
        0x3709, 0x12,
        0x3808, 0x0a,
        0x3809, 0x20,
        0x380a, 0x07,
        0x380b, 0x98,
        0x3800, 0x00,
        0x3801, 0x00,
        0x3802, 0x00,
        0x3803, 0x00,
        0x3804, 0x0a,
        0x3805, 0x3f,
        0x3806, 0x07,
        0x3807, 0xa3,
        0x3811, 0x10,
        0x3813, 0x06,
        0x3630, 0x2e,
        0x3632, 0xe2,
        0x3633, 0x23,
        0x3634, 0x44,
        0x3636, 0x06,
        0x3620, 0x64,
        0x3621, 0xe0,
        0x3600, 0x37,
        0x3704, 0xa0,
        0x3703, 0x5a,
        0x3715, 0x78,
        0x3717, 0x01,
        0x3731, 0x02,
        0x370b, 0x60,
        0x3705, 0x1a,
        0x3f05, 0x02,
        0x3f06, 0x10,
        0x3f01, 0x0a,
        0x3a08, 0x01,
        0x3a09, 0x28,
        0x3a0a, 0x00,
        0x3a0b, 0xf6,
        0x3a0d, 0x08,
        0x3a0e, 0x06,
        0x3a0f, 0x58,
        0x3a10, 0x50,
        0x3a1b, 0x58,
        0x3a1e, 0x50,
        0x3a11, 0x60,
        0x3a1f, 0x28,
        0x4001, 0x02,
        0x4004, 0x04,
        0x4000, 0x09,
        0x4837, 0x19,
        0x4800, 0x24,
        0x3503, 0x03,
        0x0100, 0x01,
};

static uint32_t ov5647_2lane_960p_init_setting[] = {
        0x0100, 0x00,
        0x0103, 0x01,
        0x3034, 0x1a,
        0x3035, 0x21,
        0x3036, 0x62,
        0x303c, 0x11,
        0x3106, 0xf5,
        0x3827, 0xec,
        0x370c, 0x03,
        0x3612, 0x59,
        0x3618, 0x00,
        0x5000, 0x06,
        0x5002, 0x40,
        0x5003, 0x08,
        0x5a00, 0x08,
        0x3000, 0x00,
        0x3001, 0x00,
        0x3002, 0x00,
        0x3016, 0x08,
        0x3017, 0xe0,
        0x3018, 0x44,
        0x301c, 0xf8,
        0x301d, 0xf0,
        0x3a18, 0x00,
        0x3a19, 0xf8,
        0x3c01, 0x80,
        0x3b07, 0x0c,
        0x3800, 0x00,
        0x3801, 0x00,
        0x3802, 0x00,
        0x3803, 0x00,
        0x3804, 0x0a,
        0x3805, 0x3f,
        0x3806, 0x07,
        0x3807, 0xa3,
        0x3808, 0x05,
        0x3809, 0x00,// output size is 0x500, 1280
        0x380a, 0x03,
        0x380b, 0xc0,//output size is 0x3c0, 960
        0x380c, 0x07,
        0x380d, 0x68,
        0x380e, 0x05,
        0x380f, 0x9B,
        0x3811, 0x0c,
        0x3813, 0x06,
        0x3814, 0x31,
        0x3815, 0x31,
        0x3630, 0x2e,
        0x3632, 0xe2,
        0x3633, 0x23,
        0x3634, 0x44,
        0x3636, 0x06,
        0x3620, 0x64,
        0x3621, 0xe0,
        0x3600, 0x37,
        0x3704, 0xa0,
        0x3703, 0x5a,
        0x3715, 0x78,
        0x3717, 0x01,
        0x3731, 0x02,
        0x370b, 0x60,
        0x3705, 0x1a,
        0x3f05, 0x02,
        0x3f06, 0x10,
        0x3f01, 0x0a,
        0x3a08, 0x01,
        0x3a09, 0x28,
        0x3a0a, 0x00,
        0x3a0b, 0xf6,
        0x3a0d, 0x08,
        0x3a0e, 0x06,
        0x3a0f, 0x58,
        0x3a10, 0x50,
        0x3a1b, 0x58,
        0x3a1e, 0x50,
        0x3a11, 0x60,
        0x3a1f, 0x28,
        0x4001, 0x02,
        0x4004, 0x04,
        0x4000, 0x09,
        0x4837, 0x16,
        0x4800, 0x24,
        0x3503, 0x03,
        0x3820, 0x41,
        0x3821, 0x06,
        0x350a, 0x00,
        0x350b, 0x10,
        0x3500, 0x00,
        0x3501, 0x1a,
        0x3502, 0xf0,
        0x3212, 0xa0,
        0x0100, 0x01,
};

static uint32_t ov5647_2lane_stream_on_setting[] = {
        0x4800, 0x34,
        0x4202, 0x00,
        0x300d, 0x00,
};

static uint32_t ov5647_2lane_stream_off_setting[] = {
        0x4800, 0x23,
        0x4202, 0x0f,
        0x300d, 0x01,
};

static uint32_t ov5647_gain_lut[] = {
        0x020,//1
        0x020,
        0x021,
        0x022,
        0x022,
        0x023,
        0x024,
        0x025,
        0x026,
        0x026,
        0x027,
        0x028,
        0x029,
        0x02A,
        0x02B,
        0x02C,
        0x02D,
        0x02E,
        0x02F,
        0x030,
        0x031,
        0x032,
        0x033,
        0x034,
        0x035,
        0x036,
        0x038,
        0x039,
        0x03A,
        0x03B,
        0x03D,
        0x03E,
        0x040,//2
        0x041,
        0x042,
        0x044,
        0x045,
        0x047,
        0x048,
        0x04A,
        0x04C,
        0x04D,
        0x04F,
        0x051,
        0x052,
        0x054,
        0x056,
        0x058,
        0x05A,
        0x05C,
        0x05E,
        0x060,
        0x062,
        0x064,
        0x067,
        0x069,
        0x06B,
        0x06D,
        0x070,
        0x072,
        0x075,
        0x077,
        0x07A,
        0x07D,
        0x080,
        0x082,
        0x085,
        0x088,
        0x08B,
        0x08E,
        0x091,
        0x094,
        0x098,
        0x09B,
        0x09E,
        0x0A2,
        0x0A5,
        0x0A9,
        0x0AD,
        0x0B1,
        0x0B5,
        0x0B8,
        0x0BD,
        0x0C1,
        0x0C5,
        0x0C9,
        0x0CE,
        0x0D2,
        0x0D7,
        0x0DB,
        0x0E0,
        0x0E5,
        0x0EA,
        0x0EF,
        0x0F5,
        0x0FA,
        0x0100,
        0x0105,
        0x010B,
        0x0111,
        0x0117,
        0x011D,
        0x0123,
        0x0129,
        0x0130,
        0x0137,
        0x013D,
        0x0144,
        0x014B,
        0x0153,
        0x015A,
        0x0162,
        0x016A,
        0x0171,
        0x017A,
        0x0182,
        0x018A,
        0x0193,
        0x019C,
        0x01A5,
        0x01AE,
        0x01B7,
        0x01C1,
        0x01CB,
        0x01D5,
        0x01DF,
        0x01EA,
        0x01F5,
        0x0200,
        0x020B,
        0x0216,
        0x0222,
        0x022E,
        0x023A,
        0x0247,
        0x0253,
        0x0260,
        0x026E,
        0x027B,
        0x0289,
        0x0297,
        0x02A6,
        0x02B5,
        0x02C4,
        0x02D4,
        0x02E3,
        0x02F4,
        0x0304,
        0x0315,
        0x0326,
        0x0338,
        0x034A,
        0x035D,
        0x036F,
        0x0383,
        0x0396,
        0x03AB,
        0x03BF,
        0x03D4,
        0x03EA
};

#ifdef __cplusplus
}
#endif

#endif
